﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using liclSolcred.Views;
using com.creditos.be.liclSolcred;
using com.creditos.util.liclUtil;

public partial class solcred_popups_FormsConUsuario : CreditosPaseBase, IFormsConUsuarioView
{
    private FormsConUsuarioPresenter oPresenter = new FormsConUsuarioPresenter();
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = 0;
        Response.CacheControl = "no-cache";
        Page.Header.Controls.Add(new LiteralControl(@"<base target=""_self"" />"));
        if (!IsPostBack) 
        {

            string strTipoCanal = Request.QueryString["tipoCanal"].Trim();
            string strCanalVenta = Request.QueryString["codigoCanal"].Trim();

            List<RepresentanteBE> lstRepresentante = new List<RepresentanteBE>();
            RepresentanteBE oRepresentante = new RepresentanteBE{ CodigoTipoCanal=int.Parse(Utilitario.DarFormatoEnteroCero(strTipoCanal)),
                                                                  CodigoCanal = int.Parse(Utilitario.DarFormatoEnteroCero(strCanalVenta))
                                                                 };


            lstRepresentante = oPresenter.ListarRepresentante(oRepresentante);

            if (lstRepresentante.Count > 0)
            {
                pnlNoExistenDatos.Visible = false;
                UIBindable.Bind(gvwUsuarios, lstRepresentante);
            }
            else pnlNoExistenDatos.Visible = true;
            

        }
    }

    protected override void DefineHandlers()
    {
        gvwUsuarios.RowCommand += new GridViewCommandEventHandler(gvwUsuarios_RowCommand);
    }

    void gvwUsuarios_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "seleccionar")
        {
            GridViewRow fila = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
            gvwUsuarios.SelectedIndex = fila.RowIndex;
            string[] arr = e.CommandArgument.ToString().Split(new char[] { '|' });
            hdfCodigoUsuario.Value = arr[0];
            hdfDescripcionUsuario.Value = arr[1];
            ScriptManager.RegisterStartupScript(this, typeof(Page), "Envio", "enviarParam();", true);

        }
    }
}
